<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\Common\Constants\StorageModeConstants;
use App\Common\Helpers\QrCode;
use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Dto\ChRoomCodeCodeDataDto;
use App\CustHub\Dto\ChRoomCodeRoomDailyDataDto;
use App\CustHub\Service\ChRoomCodeService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

#[Controller(prefix: 'ch/attract/roomCode'),ApiAuth,VerifySignature]
class ChRoomCodeController extends BaseController
{

    public array $noNeedLogin = ['exportDailyData', 'exportCodeData', 'exportRoomDailyData','getRoomQrcode','QrcodeDisplay','exportDailyCodeStatisticsByRoomRelation'];
    public array $noNeedVerifySign = ['exportDailyData', 'exportCodeData', 'exportRoomDailyData','getRoomQrcode','QrcodeDisplay','exportDailyCodeStatisticsByRoomRelation'];

    #[Inject]
    protected ChRoomCodeService $service;

    /**
     * 获取活码列表
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('list')]
    public function getRoomCodeList()
    {
        return $this->success($this->service->getRoomCodeList($this->request->all()));
    }

    /**
     * 获取活码详情
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('detail')]
    public function getRoomCodeDetail()
    {
        return $this->success($this->service->getRoomCodeDetail($this->request->all()));
    }

    /**
     * 新增活码
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('save')]
    public function saveRoomCode()
    {
        return $this->success(['id' => $this->service->saveRoomCode($this->request->all())]);
    }


    /**
     * 更新活码
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PutMapping('update')]
    public function updateRoomCode()
    {
        return $this->service->updateRoomCode($this->request->all())?$this->success():$this->error();
    }

    /**
     * 删除活码
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[DeleteMapping('delete')]
    public function deleteRoomCode()
    {
        return $this->service->deleteRoomCode($this->request->all())?$this->success():$this->error();
    }

    #[PostMapping('changeRoomStatus')]
    public function changeRoomCodeStatus()
    {
        return $this->service->roomRelatoinOperation($this->request->all())?$this->success():$this->error();
    }

    #[PostMapping('changeStatus')]
    public function changeStatus()
    {
        return $this->service->changeStatus($this->request->input('id'), $this->request->input('status'))?$this->success():$this->error();
    }

    /**
     * 活码每日数据
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('dailyData')]
    public function roomCodeDailyData()
    {
        return $this->success($this->service->getRoomCodeDailyData($this->request->all()));
    }

    #[PostMapping('updateRelationLimit')]
    public function updateRelationLimit()
    {
        return $this->service->updateRelationLimit($this->request->all()) ? $this->success() : $this->error();
    }

    #[PostMapping('getStatisticsByRoomRelation')]
    public function getStatisticsByRoomRelation()
    {
        return $this->success($this->service->getDailyCodeStatisticsByRoomRelation($this->request->all()));
    }


    /**
     * 导出每日数据
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[GetMapping('exportDailyData')]
    public function exportRoomCodeDailyData()
    {
        return $this->service->exportRoomCodeRoomDailyData($this->request->all(),ChRoomCodeRoomDailyDataDto::class);
    }

    /**
     * 按日期查看数据
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('codeData')]
    public function roomCodeCodeData()
    {
        return $this->success($this->service->getRoomCodeCodeData($this->request->all()));
    }

    #[PostMapping('getBase64Code')]
    public function getBase64Code()
    {
        return $this->success($this->service->getBase64Code($this->request->all()));
    }

    /**
     * 导出当日数据
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[GetMapping('exportCodeData')]
    public function exportRoomCodeCodeData()
    {
        return $this->service->exportRoomCodeCodeData($this->request->all(),ChRoomCodeCodeDataDto::class);
    }

    #[GetMapping('exportDailyCodeStatisticsByRoomRelation')]
    public function exportDailyCodeStatisticsByRoomRelation()
    {
        return $this->service->exportDailyCodeStatisticsByRoomRelation($this->request->all(),ChRoomCodeCodeDataDto::class);
    }

    /**
     * 获取建群号列表
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('robotList')]
    public function getRoomCodeRobotList()
    {
        return $this->success($this->service->getRoomCodeRobotList($this->request->all()));
    }

    /**
     * 添加建群号
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('addRobot')]
    public function addRoomCodeRobot()
    {
        return $this->service->addRoomCodeRobot($this->request->all()) ? $this->success() : $this->error();
    }

    /**
     * 移除建群号
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('removeRobot')]
    public function removeRoomCodeRobot()
    {
        return $this->service->removeRoomCodeRobot($this->request->all()) ? $this->success() : $this->error();
    }

    /**
     * 群列表
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('roomList')]
    public function getRoomCodeRoomList()
    {
        return $this->success($this->service->getRoomCodeRoomList($this->request->all()));
    }

    /**
     * 群每日数据
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('roomDailyData')]
    public function getRoomCodeRoomDailyData()
    {
        return $this->success($this->service->getRoomCodeRoomDailyData($this->request->all()));
    }

    /**
     * 活码样式
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[GetMapping('QrcodeDisplay')]
    public function QrcodeDisplay(): ResponseInterface
    {
        $display = container()->get(Qrcode::class)->generationRandomQrCodeWithLogo(['logo' => $this->request->input('code_logo')], StorageModeConstants::OSS);
        return $this->success($display);
    }

    /**
     * 导出群每日数据
     * @return ResponseInterface
     */
    #[GetMapping('exportRoomDailyData')]
    public function exportRoomCodeRoomDailyData()
    {
        return $this->service->exportRoomCodeRoomDailyData($this->request->all(),ChRoomCodeRoomDailyDataDto::class);
    }


    /**
     * 添加群
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('addRoom')]
    public function addRoomCodeRoom()
    {
        return $this->service->addRoomCodeRoom($this->request->all()) ? $this->success() : $this->error();
    }

    /**
     * 群排序
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('changeRoomSort')]
    public function changeRoomCodeRoomSort()
    {
        $this->service->changeRoomCodeRoomSort($this->request->all());
        return $this->success();
    }

    #[GetMapping('getRoomQrcode')]
    public function getRoomQrcode()
    {
        return $this->success($this->service->getRoomQrcode($this->request->input('id')));
    }
}